package com.example.pokemon_integrado;

import com.Manager.DrawManager;
import com.Manager.SceneManager;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class MainCode extends View implements Runnable {

	private long time = 1;	

	public int screenW, screenH;
	Context c;
	
	public MainCode(Context context, AttributeSet attr) {
		super(context, attr);

		this.screenW = context.getResources().getDisplayMetrics().widthPixels;
		this.screenH = context.getResources().getDisplayMetrics().heightPixels;
		
		c = context;
		
		Thread thread = new Thread(this);
		thread.start();
	}

	@Override
	public void run() 
	{
		while (true) {
			try {
				Thread.sleep(time);
			} catch (InterruptedException e) {
				Log.e("", "interrupcao do run()");
			}
			
			this.Update();
			postInvalidate();
		}
	}
	
	public boolean onTouchEvent(MotionEvent e)
	{
		if(e.getAction() == MotionEvent.ACTION_UP)
		{
			SceneManager.getInstance().changeScene(true);
			
			DrawManager.getInstance(c).getTouch(e.getX(), e.getY());
		}
		else if(e.getAction() == MotionEvent.ACTION_DOWN)
		{
			SceneManager.getInstance().changeScene(false);
		}
		
		return true;
	}
	
	public void draw(Canvas canvas)
	{
		Paint p = new Paint();
		super.draw(canvas);
		
		DrawManager.getInstance(c).Draw(canvas, this.screenW,this.screenH, p);
	}
	
	private void Update()
	{
		
	}

}
